package com.oocl.crm.util;

import java.io.OutputStream;

import com.oocl.crm.customer.Customer;
import com.oocl.crm.db.MyLinkedList;

public class FormatPrinter {
	public static void printHelpDoc(String cmd, OutputStream out) {
		String[] str=cmd.split(" ");
		if(str.length==1){
			System.out.printf("%-20s%-40s%-25s\n","Command","Usage","Manual");
			System.out.printf("%-20s%-40s%-25s\n","L","L name:XXX,sex:XXX...","Search user information by parameters");
			System.out.printf("%-20s%-40s%-25s\n","","L","Print the whole user information list");
			System.out.printf("%-20s%-40s%-25s\n","A","A name:XXX,sex:XXX...","Add user information");
			System.out.printf("%-20s%-40s%-25s\n","D","D XXX","Delete user information by ID");
			System.out.printf("%-20s%-40s%-25s\n","U","U XXX name:XXX,sex:XXX","Update user information by ID");
			System.out.printf("%-20s%-40s%-25s\n","O","O","Sort and print the whole user information list");
			System.out.printf("%-20s%-40s%-25s\n","H","H XXX","Show XXX help information");
			System.out.printf("%-20s%-40s%-25s\n","","H","Show help information of all the commands");
			System.out.printf("%-20s%-40s%-25s\n\n","Q","Q","Quit");
		}
		else {
			switch (str[1]) {
			case "L":
				System.out.printf("%-20s%-40s%-25s\n", "Command", "Usage",
						"Manual");
				System.out.printf("%-20s%-40s%-25s\n", "L",
						"L name:XXX,sex:XXX...",
						"Search user information by parameters");
				System.out.printf("%-20s%-40s%-25s\n\n", "", "L",
						"Print the whole user information list");
				break;
			case "A":

				System.out.printf("%-20s%-40s%-25s\n", "Command", "Usage",
						"Manual");
				System.out.printf("%-20s%-40s%-25s\n\n", "A",
						"A name:XXX,sex:XXX...", "Add user information");
				break;
			case "D":
				System.out.printf("%-20s%-40s%-25s\n", "Command", "Usage",
						"Manual");
				System.out.printf("%-20s%-40s%-25s\n\n", "D", "D XXX",
						"Delete user information by ID");
				break;
			case "U":
				System.out.printf("%-20s%-40s%-25s\n", "Command", "Usage",
						"Manual");
				System.out.printf("%-20s%-40s%-25s\n\n", "U",
						"U XXX name:XXX,sex:XXX",
						"Update user information by ID");
				break;
			case "O":
				System.out.printf("%-20s%-40s%-25s\n", "Command", "Usage",
						"Manual");
				System.out.printf("%-20s%-40s%-25s\n\n", "O", "O",
						"Sort and print the whole user information list");
				break;
			case "H":
				System.out.printf("%-20s%-40s%-25s\n", "Command", "Usage",
						"Manual");
				System.out.printf("%-20s%-40s%-25s\n", "H", "H XXX",
						"Show XXX help information");
				System.out.printf("%-20s%-40s%-25s\n\n", "", "H",
						"Show help information of all the commands");
				break;
			case "Q":
				System.out.printf("%-20s%-40s%-25s\n", "Command", "Usage",
						"Manual");
				System.out.printf("%-20s%-40s%-25s\n\n", "Q", "Q", "Quit");
				break;
			default:
				break;
			}			
		}
		
	}
	
	public static void printCustomers(Customer[] cs, OutputStream out) {
		if(cs==null){
			System.out.println("no result!");
			return;
		}
		for (int i = 0; i < cs.length; i++) {
			if(cs[i]==null)break;
			System.out.println("id:"+cs[i].getId()+" name:"+cs[i].getName()+" sex:"+cs[i].getSex()+" birthday:"+cs[i].getBirthday()+" address:"+cs[i].getAddress()+" call:"+cs[i].getCall());
		}
	}
	
	public static void printNoSuchCustomer(OutputStream out){
		System.out.println("No such customer!");
	}
	
	public static void printNeedName(){
		System.out.println("Need customer's name!");
	}
	
}
